/**
 * 设置明细页面div高度
 * 
 * @param target
 *            目标元素
 * @param bottom_h
 *            距离底部高度
 * @param min_heihgt
 *            最小高度
 * @return
 */
function setFullHeight(target, bottom_h/* 距离底部高度 */, min_heihgt/*  */) {
	target = target || $('div.panel-content');
	bottom_h = bottom_h || 15;
	min_heihgt = min_heihgt || 293;
	fullHeight(target, bottom_h, min_heihgt);

	function fullHeight(target, bottom_h/* 距离底部高度 */, min_heihgt/* 最小高度 */) {
		var height, window_h, top_h, $target = $(target), bottom_h = bottom_h ? bottom_h
				: 0, min_heihgt = min_heihgt ? min_heihgt : 0;

		function setHeight() {
			window_h = $(window).outerHeight();
			top_h = $target.offset().top;
			height = window_h - top_h - bottom_h;
			height = height > min_heihgt ? height : min_heihgt;
			$target.height(height);
		}

		$(window).on("load resize", function() {
			setHeight();
		});

		$("#search-toggle").on("click", function() {
			setHeight();
		});
	}
};

/**
 * 收起搜索框
 * 
 * @param search
 * @return
 */
function hideSearchTips(search) {
	$(search)
			.click(
					function() {
						if ($(this).data("target")) {
							var searchTips = $("#" + $(this).data("target")), searchMask = searchTips
									.siblings(".searchMask"), searchArrow = searchTips
									.find(".searchArrow");
							var left = $(this).offset().left;

							if (!searchMask.size()) {
								searchMask = $("<div>").addClass("searchMask")
										.insertAfter(searchTips);
							}

							if (searchTips.is(":visible")) {
								searchTips.hide();
								searchMask.hide();
							} else {
								$(".searchTips").hide();
								searchTips.show();
								searchArrow.offset( {
									left : left + 5
								});
								searchMask.css( {
									height : searchTips.outerHeight() + "px"
								}).show();
							}
							searchTips.find("button").click(
									function() {
										searchTips.hide().siblings(
												".searchMask").hide();
									});
							;
							(function(searchTips, searchMask, $, undefinded) {
								var timer = null, area = {
									x1 : 0,
									x2 : 0,
									y1 : 0,
									y2 : 0
								};

								timer = setTimeout(function() {
									searchTips.hide();
									searchMask.hide();
								}, 3000);

								searchTips
										.mouseenter(function() {
											$(document)
													.on(
															"mousemove",
															function(e) {
																if (timer) {
																	clearTimeout(timer);
																}
																timer = setTimeout(
																		function() {

																			var _x = e.clientX, _y = e.clientY;

																			area.x1 = searchTips
																					.offset().left;
																			area.y1 = searchTips
																					.offset().top;
																			area.x2 = area.x1
																					+ searchTips
																							.outerWidth();
																			area.y2 = area.y1
																					+ searchTips
																							.outerHeight();

																			if (_x < area.x1
																					|| _x > area.x2
																					|| _y < area.y1
																					|| _y > area.y2) {
																				searchTips
																						.hide();
																				searchMask
																						.hide();
																				$(
																						document)
																						.off(
																								"mousemove");
																			}

																		}, 100);
															});
										});

							})(searchTips, searchMask, jQuery);
						}
					});
};

/**
 * 关闭窗口
 * 
 * @return
 */
function closeWin() {
	window.open("", "_self");
	window.close();
};

/**
 * 打开全屏窗口
 * 
 * @param url
 * @param target
 * @return
 */
function openFullWin(url, form) {
	var target = '';
	form = form || {};
	if (!form.target) {
		target = 'kitWeb_' + $.utils.uuidCompactWithoutRod();
		form.target = target;
	}
	var iWidth = 1280 - 10, iHeight = 768 - 30;
	if (window.screen) {
		iWidth = screen.availWidth - 10;
		iHeight = screen.availHeight - 30;
	}
	var strFeatures = 'top=0,left=0,height=' + iHeight + ',width=' + iWidth
			+ ',resizable=no,fullscreen=yes';
	openWin(url, target, strFeatures);
};

/**
 * 打开新窗口
 * 
 * @param url
 * @param target
 * @param strFeatures
 * @return
 */
function openWin(url, target, strFeatures) {
	var objWin = window.open(url, target, strFeatures);
};
